package number_784;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    private List<String> res = new ArrayList<>();

    public List<String> letterCasePermutation(String S) {
        StringBuilder sb = new StringBuilder();
        getLetterCases(0, S, sb);
        return res;

    }

    private void getLetterCases(int index, String word, StringBuilder sb) {
        if (sb.length() == word.length()) {
            res.add(new String(sb));
            return;
        }
        if (Character.isDigit(word.charAt(index))) {
            sb.append(word.charAt(index));
            getLetterCases(index + 1, word, sb);
            sb.deleteCharAt(index);
        } else {
            for (int i = 0; i < 2; i++) {
                if (i == 0) {
                    sb.append(word.charAt(index));
                } else {
                    if (Character.isUpperCase(word.charAt(index))) {
                        sb.append(Character.toLowerCase(word.charAt(index)));
                    } else {
                        sb.append(Character.toUpperCase(word.charAt(index)));
                    }
                }
                getLetterCases(index + 1, word, sb);
                sb.deleteCharAt(index);
            }
        }

    }

    public static void main(String[] args) {
        new Solution().letterCasePermutation("a1b2");
    }
}
